import 'package:dio/dio.dart';

import '../../../../core/errors/failure.dart';
import '../../../../core/network/api_client.dart';
import '../entity/splash_bean.dart';

class SplashRepositoryImpl {
  final ApiClient apiClient;

  SplashRepositoryImpl(this.apiClient);

  Future<SplashBean> getDataForNet() async {
    final response = await apiClient.get('/xiaohuanger/update.json');
    if (response.statusCode == 200) {
      return SplashBean.fromJson(response.data);
    } else {
      throw ServerFailure('getDataForNet failed');
    }
  }

  Future<String> downloadApk(String path, String savePath, ProgressCallback? onReceiveProgress) async {
    final response = await apiClient.download(path, savePath, onReceiveProgress);
    if (response.statusCode == 200) {
      return savePath;
    } else {
      throw ServerFailure('downloadApk failed');
    }
  }
}
